<?php

// use Illuminate\Support\Facades\Schema;
use Jialeo\LaravelSchemaExtend\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class InitPayment extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('payment_records', function (Blueprint $table) {
            $table->comment = '支付记录表';
            
            $table->increments('id');
            $table->uuid('uuid')->index();

            $table->integer('union_order_id')->unsigned()->index()->nullable()->comment('统一订单id');
            $table->integer('order_id')->unsigned()->index()->nullable()->comment('订单id');

            $table->string('client_name', 25)->nullable()->comment('支付应用的名称');

            $table->string('pay_type', 20)->nullable()->index()->comment('wechat  alipay   eth');   // wechat  alipay   eth
            $table->string('pay_sub_type', 20)->nullable()->index()->comment('miniapp小程序   web网页支付  ');  // miniapp小程序   web网页支付  

            $table->char('out_trade_number', 255)->nullable()->comment('订单号'); //订单号
            $table->char('trade_number', 255)->nullable()->comment('交易号'); //交易号

            $table->integer('money')->default(0)->comment('金额');
            $table->timestamp('paid_at')->nullable()->comment('支付时间');

            $table->integer('status')->unsigned()->index()->default(1)->comment('状态1为已支付');

            $table->text('options')->nullable()->comment('options');

            $table->softDeletes();
            $table->timestamps();
        });

        Schema::create('refund_records', function (Blueprint $table) {
            $table->comment = '退款记录表';
            
            $table->increments('id');
            $table->uuid('uuid')->index();
            
            $table->integer('order_id')->unsigned()->index()->nullable()->comment('订单id');
            $table->integer('union_order_id')->unsigned()->index()->nullable()->comment('统一订单id');
            $table->integer('tenant_id')->unsigned()->index()->nullable()->comment('店铺id');

            $table->tinyInteger('method')->index()->default(1)->comment('支付类型1为微信支付，  2为支付宝');   // 支付类型1为微信支付，  2为支付宝
            $table->char('sub_method', 30)->nullable()->index()->comment('支付类型');  // 支付类型

            $table->char('out_refund_number', 255)->nullable()->comment('订单号'); //订单号
            $table->char('refund_number', 255)->nullable()->comment('交易号'); //交易号

            $table->integer('money')->default(0)->comment('金额');
            $table->timestamp('refunded_at')->nullable()->comment('退款时间');

            $table->integer('status')->unsigned()->index()->default(1);

            $table->text('options')->nullable() ;

            $table->softDeletes();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('payment_records');
        Schema::dropIfExists('refund_records');
    }
}
